from typing import Tuple

class Scheduler:
    def __init__(self):
        
        self.n = 0
        self.total_vcpu = 0
        self.total_mem = 0
        self.num_of_ins = 0
        self.used_vcpu: List[int] = []
        self.used_mem: List[int] = []
        self.id_to_pos: List[int] = []
        self.id_to_vcpu: List[int] = []
        self.id_to_mem: List[int] = []
         

#初始化 n 台全空的主机， 每台有 c 个 VCPU 和 m GB 内存
    def init(self, n: int, c: int, m: int):
        self.n = n;
        for i in self.used_vcpu:
            self.used_vcpu[i]  *= c
            self.used_mem[i] *= m

#需要选手返回给系统在编号为<machine_id>的机器上创建该虚拟机。 
# 如果需要扩容， 那么选手还需返回扩容台数（不扩容返回0） ，
#  这些新增物理主机的编号在当前物理主机的编号上依次递增
    def create(self, id: int, vcpu: int, mem: int) -> Tuple[int, int]:
       
    # Note: Current method is only for testing, score will be 0 due to illegal creation
        if pos < 0 or pos >= len(self.used_vcpu):
            return False
        if (self.used_vcpu[pos] + vcpu > self.total_vcpu) or (self.used_mem[pos] + mem > self.total_mem):
            return False
        self.id_to_pos[id] = pos
        self.used_vcpu[pos] += vcpu
        self.used_mem[pos] += mem
        return True 
        return (0, 0)  


#表示删除编号<id>的虚拟机，
    def remove(self, id: int):
        pos = self.id_to_pos[id] # pos是物理主机  id是虚拟主机的id号
        vcpu = self.id_to_vcpu[id]
        mem = self.id_to_mem[id]
        self.used_vcpu[pos] -= vcpu
        self.used_mem[pos] -= mem
